# Legislators as Lobbyists #
# FIGURE 1 #

require(RCurl)
require(xlsx)
require(zipcode)
require(choroplethr)

# Import Census data

urlfile <-'http://www.psc.isr.umich.edu/dis/census/Features/tract2zip/MedianZIP-3.xlsx'
destfile <- "census20062010.xlsx"
download.file(urlfile, destfile, mode="wb")
census <- read.xlsx2(destfile, sheetName = "Median")

census <- census[c('Zip','Median..')]
names(census) <- c('Zip','Median')
census$Median <- as.character(census$Median)
census$Median <- as.numeric(gsub(',','',census$Median))
print(head(census,5))

data(zipcode)
census$Zip <- clean.zipcodes(census$Zip)

# Import TAA data

taa<-read.csv("taa_map.csv", header=TRUE)

# Figure 

taa$region = taa$cty_fips
taa$value = taa$totaltaa
map_taapetitions<-county_choropleth(taa,
                                    legend = "Total Number of TAA Petitions")

map_taapetitions
